package com.thinkfit.jy.adapter;

import android.content.Context;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.thinkfit.jy.R;
import com.thinkfit.jy.bean.WifiBean;
import com.thinkfit.jy.bean.WifiConnectState;

public class WifiAdapter extends BaseQuickAdapter<WifiBean, BaseViewHolder> {
    private Context mContext;

    public WifiAdapter(Context context) {
        super(R.layout.item_wifi);
        mContext = context;
    }

    @Override
    protected void convert(final BaseViewHolder helper, WifiBean item) {
        helper.setText(R.id.tvName, item.getWifiName());
        if(item.getState() == WifiConnectState.Connected){
            helper.setGone(R.id.tvStatus, false)
                    .setText(R.id.tvStatus, mContext.getString(R.string.app_connected))
                    .setImageResource(R.id.ivStatus, R.drawable.icon_chose_1);
        }else if (item.getState() == WifiConnectState.Connecting) {
            helper.setGone(R.id.tvStatus, false)
                    .setText(R.id.tvStatus, mContext.getString(R.string.app_connecting))
                    .setImageResource(R.id.ivStatus, R.drawable.icon_net_lock);
        }else{
            helper.setGone(R.id.tvStatus, false)
                    .setText(R.id.tvStatus, mContext.getString(R.string.app_not_connect))
                    .setImageResource(R.id.ivStatus, R.drawable.icon_net_lock);
        }
        try {
            int value = Integer.parseInt(item.getLevel().replace("-", ""));
            if (value == 3) {//大于90信号弱
                helper.setImageResource(R.id.ivSignal, R.drawable.icon_set_wifi_1);
            } else if (value == 2) {//50-90信号良好
                helper.setImageResource(R.id.ivSignal, R.drawable.icon_set_wifi_2);
            } else {//小于50信号强
                helper.setImageResource(R.id.ivSignal, R.drawable.icon_set_wifi_3);
            }
        } catch (Exception e) {

        }

    }


    public interface WifiListener {
        void isConnect(int position);
    }


}
